package main;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class TimeLine extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7163775881460794525L;
	private TimeLineSlider slider;
	public int labelWidth = 100;
	JLabel beginTimeLabel;
	JLabel endTimeLabel;
	
	public TimeLine(Date currentTime, Date min, Date max)
	{
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		Date beginTime = min;
		Date endTime = max;
		
	    SimpleDateFormat ft = new SimpleDateFormat ("dd / MM \n HH:mm:ss");

		this.beginTimeLabel = new JLabel(ft.format(beginTime));
		this.beginTimeLabel.setPreferredSize(new Dimension(labelWidth, 0));
		this.beginTimeLabel.setHorizontalAlignment(JLabel.CENTER);
		
		setSlider(new TimeLineSlider(min.getTime(), max.getTime()));
		
		this.endTimeLabel = new JLabel(ft.format(endTime));
		this.endTimeLabel.setPreferredSize(new Dimension(labelWidth,0));
		this.endTimeLabel.setHorizontalAlignment(JLabel.CENTER);
		
		c.gridy = 0;
		c.gridx = 0;
		c.fill = GridBagConstraints.VERTICAL;
		c.anchor = GridBagConstraints.NORTH;
		this.add(beginTimeLabel,c);
		c.gridx = 1;
		c.weightx = 1.0f;
		c.fill = GridBagConstraints.BOTH;
		this.add(getSlider(),c);
		c.fill = GridBagConstraints.VERTICAL;
		c.weightx = 0.0f;
		c.gridx = 2;
		this.add(endTimeLabel,c);
		
	}
	
	public void setWidth(int width)
	{
		
	}

	public long getLowerValue() {
		return getSlider().beginTime + getSlider().lowerValue;
	}

	public long getUpperValue() {
		// TODO Auto-generated method stub
		return getSlider().beginTime + getSlider().upperValue;
	}

	public void setCurrentValue(long value) {
		// TODO Auto-generated method stub
		this.slider.setValue((int)(value - this.slider.beginTime));
	}

	public boolean sliderisDragging() {
		// TODO Auto-generated method stub
		return this.slider.isDragging();
	}

	public TimeLineSlider getSlider() {
		return slider;
	}

	public void setSlider(TimeLineSlider slider) {
		this.slider = slider;
	}
	
	public long getBeginTime()
	{
		return this.slider.beginTime;
	}

	public long getValue() {
		// TODO Auto-generated method stub
		return this.slider.currentValue + this.slider.getBeginTime();
	}
}
